package com.example.controller;

import com.example.service.HazelcastService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestIAtomicLongController {

    Logger logger = LoggerFactory.getLogger(getClass());

    public static final String IAtomicLong = "IAtomicLong_IAtomicLong-IAtomicLong";

    @Resource
    private HazelcastService hazelcastService;

    /***
     * 设置计数器
     * @return
     */
    @RequestMapping("setAtomicLong")
    public long setiAtomicLong() {
        com.hazelcast.cp.IAtomicLong iAtomicLong = hazelcastService.getIAtomicLong(IAtomicLong);
        iAtomicLong.incrementAndGet();
        return iAtomicLong.get();
    }

    /***
     * 获取计数器
     * @return
     */
    @RequestMapping("getAtomicLong")
    public long getiAtomicLong() {
        com.hazelcast.cp.IAtomicLong iAtomicLong = hazelcastService.getIAtomicLong(IAtomicLong);
        return iAtomicLong.get();
    }
}
